package o;

import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import com.huawei.gamebox.plugin.gameservice.bean.GameSubAcct;
import com.huawei.gamebox.plugin.gameservice.bean.GetGameAuthSignResp;
import com.huawei.gamebox.plugin.gameservice.bean.GetGameSubAccResp;
import com.huawei.hms.support.api.entity.pay.HwPayConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import java.util.List;
import o.faw.d;
import o.faw.e;
import org.json.JSONObject;

public class ezu implements AccountBussinessListener {
    private static ezu ॱ;
    private Context ˊ;
    private fad ˋ;
    private eyz ˎ;
    private GameInfo ˏ;

    interface c {
        void ˋ();

        void ॱ(String str, String str2);
    }

    public static synchronized ezu ˊ() {
        ezu o_ezu;
        synchronized (ezu.class) {
            if (ॱ == null) {
                ॱ = new ezu();
            }
            o_ezu = ॱ;
        }
        return o_ezu;
    }

    public void ˎ(Context context, GameInfo gameInfo, eyz o_eyz, fad o_fad) {
        this.ˊ = context;
        this.ˏ = gameInfo;
        this.ˎ = o_eyz;
        this.ˋ = o_fad;
        eoj.ˋ().ˎ("GameServiceLoginManager", this);
    }

    public void ˋ() {
        if (!ˏ()) {
            return;
        }
        if (this.ˎ.ˋ() == 1) {
            ˎ();
        } else {
            fab.ˎ().ˏ(this.ˏ, "login|init", this.ˋ);
        }
    }

    public void ॱ() {
        if (!ˏ()) {
            return;
        }
        if (ezl.ˎ().ˏ(this.ˊ)) {
            ezm anonymousClass5 = new ezm(this) {
                final /* synthetic */ ezu ˊ;

                {
                    this.ˊ = r1;
                }

                public void ˊ(ccm o_ccm) {
                    if (o_ccm != null) {
                        this.ˊ.ॱ(o_ccm.ˊ());
                    }
                }

                public void ˏ(int i, String str) {
                    Logger.e("GameServiceLoginManager", "the account is login failed, errorCode:" + i + ", errorDesc:" + str);
                    if (this.ˊ.ˎ.ˎ() == 1 && (i == 39 || i == 40)) {
                        fab.ˎ().ˏ(this.ˊ.ˏ, "login|start", this.ˊ.ˋ);
                        try {
                            StringBuilder append = new StringBuilder(256).append(KeyAndValue.NUMBER_01).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(ezq.ˏ().ˎ(this.ˊ.ˏ.getPackageName())).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(this.ˊ.ˏ.getPackageName()).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(this.ˊ.ˏ.getAppId()).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(this.ˊ.ˏ.getSdkVersionCode()).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append("CloudAccount.getAccountsByType").append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(System.currentTimeMillis()).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(System.currentTimeMillis()).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(Build.MODEL).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(doo.ʼ(ContentManager.getInstant().getContext())).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append("").append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(i);
                            dgh.ॱ(ContentManager.getInstant().getContext(), "15070106", append.toString());
                        } catch (Throwable e) {
                            Logger.ˋ("GameServiceLoginManager", "add Hianalytics Log", e);
                        }
                    } else if (this.ˊ.ˎ.ˎ() == 1 && i == 1) {
                        fab.ˎ().ˏ(this.ˊ.ˏ, "login|auth", this.ˊ.ˋ);
                    } else {
                        this.ˊ.ˏ(this.ˊ.ॱ(i));
                    }
                }
            };
            anonymousClass5.ˎ(true);
            ezl.ˎ().ˋ(this.ˊ, false, false, anonymousClass5);
        } else if (this.ˎ.ˎ() == 1) {
            fab.ˎ().ˏ(this.ˏ, "login|start", this.ˋ);
        } else {
            ˏ(ॱ(-1));
        }
    }

    public void ॱ(String str) {
        if (ˏ()) {
            if (!TextUtils.isEmpty(this.ˎ.ˊ())) {
                String[] split = this.ˎ.ˊ().split("\\|");
                if (split.length == 2 && str.equals(split[1]) && !str.equals(split[0])) {
                    String str2 = split[0];
                    ezq.ˏ().ˏ(1, str2, str, this.ˏ.getPackageName());
                    ˏ(ˋ(str2, "", "", ""));
                    return;
                }
            }
            ˏ(ˋ(ˊ(str), "", "", ""));
        }
    }

    public void ˊ(final ccm o_ccm) {
        if (ˏ()) {
            eod.ˊ(this.ˊ);
            String ˊ = o_ccm.ˊ();
            ˎ(ˊ, o_ccm.ˋ(), ˊ(ˊ), o_ccm, new c(this) {
                final /* synthetic */ ezu ˎ;

                public void ॱ(String str, String str2) {
                    this.ˎ.ˎ(o_ccm, str, str2);
                }

                public void ˋ() {
                    this.ˎ.ˏ(this.ˎ.ॱ(-1));
                }
            });
        }
    }

    private void ˎ() {
        ezm anonymousClass3 = new ezm(this) {
            final /* synthetic */ ezu ˊ;

            {
                this.ˊ = r1;
            }

            public void ˊ(ccm o_ccm) {
                if (o_ccm != null) {
                    this.ˊ.ˊ(o_ccm);
                }
            }

            public void ˏ(int i, String str) {
                Logger.e("GameServiceLoginManager", "stAuth onError, errorCode:" + i + ", errorDesc:" + str);
                if (this.ˊ.ˎ.ˎ() == 1) {
                    fab.ˎ().ˏ(this.ˊ.ˏ, "login|auth", this.ˊ.ˋ);
                } else {
                    this.ˊ.ˏ(this.ˊ.ॱ(i));
                }
            }
        };
        anonymousClass3.ˎ(true);
        ezl.ˎ().ˋ(this.ˊ, true, true, anonymousClass3);
    }

    public void ˏ(String str) {
        if (ˏ()) {
            try {
                if (this.ˋ != null && this.ˎ != null) {
                    this.ˋ.ˋ(this.ˎ.ॱ(), str);
                }
            } catch (Throwable e) {
                Logger.ˋ("GameServiceLoginManager", "Login RemoteException:", e);
            } catch (Throwable e2) {
                Logger.ˋ("GameServiceLoginManager", "Login Exception:", e2);
            }
        }
    }

    private String ˋ(String str, String str2, String str3, String str4) {
        String str5 = "";
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("rtnCode", 0);
            jSONObject.put("userID", str);
            jSONObject.put(HwPayConstant.KEY_USER_NAME, str2);
            jSONObject.put("gameAuthSign", str3);
            jSONObject.put("ts", str4);
            str5 = jSONObject.toString();
        } catch (Throwable e) {
            Logger.ˋ("GameServiceLoginManager", "getSucessResultJson JSONException:", e);
        }
        return str5;
    }

    public String ॱ(int i) {
        String str = "";
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("rtnCode", i);
            str = jSONObject.toString();
        } catch (Throwable e) {
            Logger.ˋ("GameServiceLoginManager", "getLoginResultJson JSONException:", e);
        }
        return str;
    }

    private boolean ˏ() {
        if (this.ˊ == null) {
            Logger.e("GameServiceLoginManager", "check the param [mContext] is null");
            return false;
        } else if (this.ˏ == null) {
            Logger.e("GameServiceLoginManager", "check the param [mGameInfo] is null");
            return false;
        } else if (this.ˎ == null) {
            Logger.e("GameServiceLoginManager", "check the param [mRequest] is null");
            return false;
        } else if (this.ˋ != null) {
            return true;
        } else {
            Logger.e("GameServiceLoginManager", "check the param [mCallback] is null");
            return false;
        }
    }

    public void onAccountBusinessResult(ccp o_ccp) {
        if (Logger.ˎ()) {
            Logger.ˏ("GameServiceLoginManager", "onAccountBusinessResult:" + o_ccp.ˎ);
        }
        if (o_ccp.ˎ == 103) {
            if (Logger.ˎ()) {
                Logger.ˏ("GameServiceLoginManager", "clear game service account info");
            }
            ezq.ˏ().ˏˏ();
            ezg.ॱ().ˏ();
        }
    }

    private String ˊ(String str) {
        Object ˏ = ezq.ˏ().ˏ(this.ˏ.getPackageName());
        CharSequence ˎ = ezq.ˏ().ˎ(this.ˏ.getPackageName());
        if (!TextUtils.isEmpty(ˎ) && !TextUtils.isEmpty(ˏ) && ˏ.equals(str)) {
            return ˎ;
        }
        ezq.ˏ().ˏ(1, str, str, this.ˏ.getPackageName());
        return str;
    }

    private void ˎ(String str, String str2, String str3, ccm o_ccm, c cVar) {
        if (cVar != null) {
            if (dof.ॱ(str) || dof.ॱ(str3)) {
                cVar.ˋ();
                return;
            }
            String str4;
            if (dof.ॱ(str2)) {
                str4 = "";
            } else {
                str4 = str2;
            }
            if (str3.equals(str)) {
                cVar.ॱ(str3, str2);
                return;
            }
            final String str5 = str3;
            final c cVar2 = cVar;
            final String str6 = str;
            cfw.ˎ(ezc.ˋ(this.ˏ, o_ccm), new IServerCallBack(this) {
                final /* synthetic */ ezu ˏ;

                public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                    String str = "";
                    if ((responseBean instanceof GetGameSubAccResp) && responseBean.getResponseCode() == 0 && responseBean.getRtnCode_() == 0) {
                        List<GameSubAcct> ˎ = ((GetGameSubAccResp) responseBean).ˎ();
                        if (!(ˎ == null || ˎ.isEmpty())) {
                            String ˎ2;
                            int i;
                            for (GameSubAcct gameSubAcct : ˎ) {
                                if (str5.equals(gameSubAcct.ˏ())) {
                                    ˎ2 = gameSubAcct.ˎ();
                                    i = 1;
                                    break;
                                }
                            }
                            i = 0;
                            ˎ2 = str;
                            if (i != 0) {
                                cVar2.ॱ(str5, str4 + "\\" + ˎ2);
                                return;
                            }
                        }
                    }
                    ezq.ˏ().ˏ(1, str6, str6, this.ˏ.ˏ.getPackageName());
                    cVar2.ॱ(str6, str4);
                }

                public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
                }
            });
        }
    }

    private void ॱ(final String str, final String str2, ccm o_ccm, @NonNull final GetGameAuthSignResp getGameAuthSignResp) {
        faw.ˏ().ˎ(o_ccm);
        faw.ˏ().ˎ(this.ˊ, this.ˏ, e.GAME_STARTUP, getGameAuthSignResp.ˋ(), new d(this) {
            final /* synthetic */ ezu ˋ;

            public void ˏ(int i) {
                if (i == -1 || i == 1) {
                    StringBuilder append = new StringBuilder(64).append(KeyAndValue.NUMBER_01).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(ezq.ˏ().ˎ(this.ˋ.ˏ.getPackageName())).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(this.ˋ.ˏ.getPackageName()).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(this.ˋ.ˏ.getAppId()).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(this.ˋ.ˏ.getSdkVersionCode()).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append("");
                    dgh.ॱ(this.ˋ.ˊ, "15100706", append.toString());
                }
                if (faw.ˏ().ॱ(i)) {
                    this.ˋ.ˏ(this.ˋ.ˋ(str, str2, getGameAuthSignResp.ॱ(), getGameAuthSignResp.ˊ()));
                } else {
                    this.ˋ.ˏ(this.ˋ.ॱ(110034));
                }
            }
        });
    }

    private void ˎ(final ccm o_ccm, final String str, final String str2) {
        new fac("", null).ॱ(this.ˏ, o_ccm, new IServerCallBack(this) {
            final /* synthetic */ ezu ˋ;

            public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                if ((responseBean instanceof GetGameAuthSignResp) && responseBean.getResponseCode() == 0) {
                    GetGameAuthSignResp getGameAuthSignResp = (GetGameAuthSignResp) responseBean;
                    if (getGameAuthSignResp.getRtnCode_() == 0) {
                        this.ˋ.ॱ(str, str2, o_ccm, getGameAuthSignResp);
                        return;
                    }
                    Logger.e("GameServiceLoginManager", "GetGameAuthSign failed rtnCode:" + getGameAuthSignResp.getRtnCode_());
                    if (this.ˋ.ˎ.ˎ() == 1) {
                        fab.ˎ().ˏ(this.ˋ.ˏ, "login|auth", this.ˋ.ˋ);
                        return;
                    } else {
                        this.ˋ.ˏ(this.ˋ.ॱ(getGameAuthSignResp.getRtnCode_()));
                        return;
                    }
                }
                Logger.e("GameServiceLoginManager", "GetGameAuthSign failed responseCode:" + responseBean.getResponseCode());
                this.ˋ.ˏ(this.ˋ.ॱ(responseBean.getResponseCode()));
            }

            public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
            }
        });
    }
}
